package ru.vsu.cs.piit.vokod.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Галчонок
 */
@Entity
@Table(name = "group_of_diagnosis")
@NamedQueries({@NamedQuery(name = "GroupOfDiagnosis.findAll", query = "SELECT g FROM GroupOfDiagnosis g"), @NamedQuery(name = "GroupOfDiagnosis.findByGroupOfDiagnosisId", query = "SELECT g FROM GroupOfDiagnosis g WHERE g.groupOfDiagnosisId = :groupOfDiagnosisId"), @NamedQuery(name = "GroupOfDiagnosis.findByCode", query = "SELECT g FROM GroupOfDiagnosis g WHERE g.code = :code")})
public class GroupOfDiagnosis implements Serializable, Comparable<GroupOfDiagnosis> {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "group_of_diagnosis_id")
    private Integer groupOfDiagnosisId;
    @Column(name = "code")
    private String code;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "groupOfDiagnosis")
    private List<Diagnos> diagnosisCollection;

    public GroupOfDiagnosis() {
    }

    public GroupOfDiagnosis(Integer groupOfDiagnosisId) {
        this.groupOfDiagnosisId = groupOfDiagnosisId;
    }

    public Integer getGroupOfDiagnosisId() {
        return groupOfDiagnosisId;
    }

    public void setGroupOfDiagnosisId(Integer groupOfDiagnosisId) {
        this.groupOfDiagnosisId = groupOfDiagnosisId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public List<Diagnos> getDiagnosisCollection() {
        return diagnosisCollection;
    }

    public void setDiagnosisCollection(List<Diagnos> diagnosisCollection) {
        this.diagnosisCollection = diagnosisCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (groupOfDiagnosisId != null ? groupOfDiagnosisId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GroupOfDiagnosis)) {
            return false;
        }
        GroupOfDiagnosis other = (GroupOfDiagnosis) object;
        if ((this.groupOfDiagnosisId == null && other.groupOfDiagnosisId != null) || (this.groupOfDiagnosisId != null && !this.groupOfDiagnosisId.equals(other.groupOfDiagnosisId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getCode();
    }

    public int compareTo(GroupOfDiagnosis o) {
        if (this.equals(o)) return 0;
        if (this.getGroupOfDiagnosisId()<o.groupOfDiagnosisId) return -1;
        return 1;
    }

}
